package com.gs.study.cfg;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/** 
 * @author gaoshang 
 * @date 创建时间：2018年5月18日 下午2:10:13 
 * @version 1.0 
 * @parameter  
 * @since  
 * @return  
 */
@Configuration
@ComponentScan({"com.gs.study.service.impl.AsyncServiceImpl"})
@PropertySource(ignoreResourceNotFound = true, value = {"classpath:/log4j.properties"}, name = "email")
//开始异步支持
public class AopConfig implements AsyncConfigurer{
	 @Override
	    public Executor getAsyncExecutor() {
	         //线程池
	        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
	        taskExecutor.setCorePoolSize(10);
	        taskExecutor.setMaxPoolSize(20);
	        taskExecutor.setQueueCapacity(200);
	        taskExecutor.setKeepAliveSeconds(60);
	        taskExecutor.initialize();
	        taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
	        return taskExecutor;
	    }

	    @Override
	    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
	         return null;
	    }
}
